using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_CommonHeroHead : UIBaseNode
    {

        #region Template Generate,don't modify
        protected partial class UIB_UIN_CommonHeroHead
        {
            #region ObjectBinding Generate
            public IQIGame.Onigao.Framework.ExArtSpriteNum frameQuality { protected set; get; }
            public IQIGame.Onigao.Framework.ExImage imageIcon { protected set; get; }
            public UnityEngine.GameObject starRoot { protected set; get; }
            public UnityEngine.GameObject star { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textLv { protected set; get; }
            public UnityEngine.GameObject classType { protected set; get; }
            public IQIGame.Onigao.Framework.ExArtSpriteNum classTypeIcon { protected set; get; }
            public UnityEngine.GameObject attributeType { protected set; get; }
            public IQIGame.Onigao.Framework.ExArtSpriteNum attributeTypeIcon { protected set; get; }
            public UnityEngine.GameObject tagWorking { protected set; get; }
            public UnityEngine.GameObject tagUsed { protected set; get; }
            public UnityEngine.GameObject gobjSelected { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExArtSpriteNum>("frameQuality", out var __tbv0);
                this.frameQuality = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExImage>("imageIcon", out var __tbv1);
                this.imageIcon = __tbv1;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("starRoot", out var __tbv2);
                this.starRoot = __tbv2;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("star", out var __tbv3);
                this.star = __tbv3;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textLv", out var __tbv4);
                this.textLv = __tbv4;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("classType", out var __tbv5);
                this.classType = __tbv5;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExArtSpriteNum>("classTypeIcon", out var __tbv6);
                this.classTypeIcon = __tbv6;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("attributeType", out var __tbv7);
                this.attributeType = __tbv7;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExArtSpriteNum>("attributeTypeIcon", out var __tbv8);
                this.attributeTypeIcon = __tbv8;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("tagWorking", out var __tbv9);
                this.tagWorking = __tbv9;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("tagUsed", out var __tbv10);
                this.tagUsed = __tbv10;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("gobjSelected", out var __tbv11);
                this.gobjSelected = __tbv11;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields & properties
        ListScrollAdapter<UIN_CommonDarkLight> _listStar = null;

        private int bigStar = 0;

        protected UIB_UIN_CommonHeroHead ui { get; set; }
        #endregion

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_CommonHeroHead();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this.ui.tagUsed.SetActive(false);
            this.ui.tagWorking.SetActive(false);
            this._listStar = this.InitListScroll<UIN_CommonDarkLight>(this.ui.star, this.OnStarChanged);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        protected override void OnDispose()
        {
            this.bigStar = 0;
        }

        public void Show(HeroData heroData)
        {
            _Show(heroData);
        }

        private bool _Show(HeroData heroData)
        {
            if (heroData == null)
            {
                this.Hide();
                return false;
            }

            this.Show();
            this.ui.tagUsed.SetActive(false);
            this.ui.tagWorking.SetActive(false);

            var cfgHero = heroData.cfgData;
            var cfgHeroSkin = heroData.cfgSkin;
            this.bigStar = heroData.cfgStar.BigStar;

            this.SetIcon(cfgHeroSkin.HeroHeadImage_fullPath);

            this._listStar.RefillCells(APIUIConst.HeroDefautMaxStar);
            this.SetLv(heroData.level);
            this.ui.classTypeIcon.SetInt(cfgHero.HeroClass);
            this.ui.attributeTypeIcon.SetInt(cfgHero.HeroElementType);

            // int quality = 0;
            // this.SetQuality(APIUIConst.GetItemQualityImg(quality));
            return true;
        }

        public void ShowFormation(HeroData heroData, bool isStateCurrPos, bool isStateWorking)
        {
            if (_Show(heroData))
            {
                this.ui.tagUsed.SetActive(isStateCurrPos);
                this.ui.tagWorking.SetActive(isStateWorking);
            }
        }

        void OnStarChanged(UIN_CommonDarkLight item, int index)
        {
            int nCurr = index + 1;
            bool isLight = (bigStar >= nCurr);
            item.Show(isLight);
        }

        public void SetQuality(int quality)
        {
            this.ui.frameQuality.SetInt(quality);
        }

        public void SetIcon(string img)
        {
            this.SetImageSprite(this.ui.imageIcon, img);
        }

        public void SetLv(int lv)
        {
            this.ui.textLv.text = lv.ToString();
        }

        public void SetSelected(bool selected)
        {
            this.ui.gobjSelected.SetActive(selected);
        }
    }
}
